package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.apis.admin.AdChannelControllerApi;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理",tags = "频道管理-AdChannel",description = "频道管理API")
public class AdChannelController implements AdChannelControllerApi {
    @Autowired
    private AdChannelService adChannelService;

    @PostMapping("/list")
    @Override
    @ApiOperation(value = "条件分页查询频道列表")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        ResponseResult responseResult = adChannelService.findByNameAndPage(dto);
        return responseResult;
    }

    @PostMapping("/save")
    @Override
    @ApiOperation(value = "添加频道")
    public ResponseResult insert(@RequestBody AdChannel adChannel) {
        return adChannelService.insert(adChannel);
    }


    @PutMapping("/update")
    @Override
    @ApiOperation(value = "修改频道")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.update(adChannel);
    }

    @DeleteMapping("/del/{id}")
    @Override
    @ApiOperation(value = "删除频道")
    public ResponseResult delete(@PathVariable("id") Integer id) {
        return adChannelService.delete(id);
    }


    @GetMapping("/channels")
    @Override
    public ResponseResult findAll() {
        List<AdChannel> channels = adChannelService.list();
        return ResponseResult.okResult(channels);
    }

    @Override
    @ApiOperation(value = "频道排序")
    public ResponseResult order(Integer ord) {
        return null;
    }

    @Override
    @ApiOperation(value = "频道上移")
    public ResponseResult up(Integer ord) {
        return null;
    }

    @Override
    @ApiOperation(value = "添加下移")
    public ResponseResult down(Integer ord) {
        return null;
    }
}
